import fetch from './fetch'

const bigToastProps = {
	duration: 5000,
	className: 'tkon-toast'
}

export function productDetail(productId) {
	return fetch({
		url: 'insurance/product/productDetail',
		method: 'get',
		params: { productId },
		toastProps: bigToastProps
	})
}

export function customerList(params) {
	return fetch({
		url: 'insurance/insure/customerList',
		method: 'get',
		params
	})
}

// 带出信息
export function customerById(customerId) {
	return fetch({
		url: 'insurance/insure/customerById',
		method: 'get',
		params: { customerId }
	})
}
// 文件上传
export function uploadFile(data) {
	const fd = new FormData()
	for (let key in data) {
		fd.append(key, data[key])
	}
	return fetch({
		url: 'insurance/uploadFile',
		method: 'post',
		data: fd,
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	})
}
// 文件移除
export function removeFile(data) {
	return fetch({
		url: 'insurance/removeById',
		method: 'post',
		data,
		params: data
	})
}

// 营业执照识别
export function licenseOcr({ fileId }) {
	return fetch({
		url: 'insurance/licenseOcr',
		method: 'get',
		params: { fileId }
	})
}

// 验证码
export function sendSMSCode(mobile) {
	return fetch({
		url: 'insurance/insure/sendSMSCode',
		method: 'post',
		params: { mobile }
	})
}

// 保存投保人
export function saveInsure(data, params) {
	return fetch({
		url: 'insurance/insure/confirm1',
		method: 'post',
		data,
		params,
		headers: {
			'Content-Type': 'application/json'
		}
	})
}

// 保存被保人
export function saveBeibao(data, params) {
	return fetch({
		url: 'insurance/insure/confirm2',
		method: 'post',
		data,
		params,
		headers: {
			'Content-Type': 'application/json'
		}
	})
}

// 验证码
export function getGuarantee(productId) {
	return fetch({
		url: 'insurance/product/guarantee',
		method: 'post',
		params: { productId }
	})
}

// 人员表头
export function queryTargetByType(productId) {
	return fetch({
		url: 'insurance/product/queryTargetByType',
		method: 'post',
		params: { productId }
	})
}

// 人员表数据
export function querySubjectData(id) {
	return fetch({
		url: 'insurance/product/querySubjectData',
		method: 'post',
		params: { id, page: 1, limit: 99999 }
	})
}

// 导入上传
export function importPerson({ file, id, ...rest }) {
	const fd = new FormData()
	fd.append('file', file)
	fd.append('id', id)
	for (let key in rest) {
		fd.append(key, rest[key])
	}
	return fetch({
		url: 'insurance/product/importPerson',
		method: 'post',
		data: fd,
		parmas: { id },
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	})
}

// 模板下载
export function downloadExcel(params) {
	return fetch({
		url: 'insurance/product/downloadExcel',
		method: 'get',
		params,
		responseType: 'blob'
	})
}
export function downloadBatchInsuranceExcel(params) {
	return fetch({
		url: 'CrmContract/downloadBatchInsuranceExcel',
		method: 'get',
		params,
		responseType: 'blob'
	})
}

// 生成订单号
export function createBusiness(params) {
	return fetch({
		url: 'insurance/insure/createBusiness',
		method: 'get',
		params
	})
}

// 保障期限保存
export function saveQixian(businessId, data) {
	return fetch({
		url: 'insurance/insure/confirm2',
		method: 'post',
		params: { businessId },
		data,
		headers: {
			'Content-Type': 'application/json'
		}
	})
}

// 人员保存
export function savePerson(businessId, data) {
	return fetch({
		url: 'insurance/product/savePerson?type=business',
		method: 'post',
		params: { id: businessId },
		data,
		headers: {
			'Content-Type': 'application/json'
		}
	})
}

// 保存
export function save({ businessId, same }) {
	return fetch({
		url: 'insurance/insure/save',
		method: 'get',
		params: { id: businessId, businessId, same },
		data: { id: businessId, businessId, same },
		headers: {
			'Content-Type': 'application/json'
		}
	})
}

// 编辑获取
export function getBusinessById(businessId) {
	return fetch({
		url: 'insurance/insure/getBusinessById',
		method: 'get',
		params: { id: businessId }
	})
}

// 获取盖章信息
export function getSignatures(businessId) {
	return fetch({
		url: 'insurance/insure/getSignatures',
		method: 'get',
		params: { businessId }
	})
}

// 提交手动盖章投保书
export function printSeal(data, params) {
	return fetch({
		url: 'insurance/insure/printSeal',
		method: 'post',
		data,
		params,
		headers: {
			'Content-Type': 'application/json'
		}
	})
}

// 提交电子盖章投保书
export function saveAndSignature(data, params) {
	return fetch({
		url: 'insurance/insure/saveAndSignature',
		method: 'post',
		data,
		params,
		headers: {
			'Content-Type': 'application/json'
		}
	})
}

// 电子签章验证码
export function sendSignSMSCode(mobile, params) {
	return fetch({
		url: 'insurance/insure/sendSignSMSCode',
		method: 'post',
		data: { mobile },
		params,
		headers: {
			'Content-Type': 'application/json'
		}
	})
}

// 电子签章验证码
export function paymentDetail(businessId) {
	return fetch({
		url: 'insurance/payment/detail',
		method: 'post',
		params: { businessId }
	})
}

// 电子回单提交
export function saveReceipt(businessId, data) {
	return fetch({
		url: 'insurance/payment/saveReceipt',
		method: 'post',
		params: { businessId },
		data,
		headers: {
			'Content-Type': 'application/json'
		}
	})
}

// 展品列表
export function list(businessId, data) {
	return fetch({
		url: 'insurance/product/list',
		method: 'get'
	})
}

// 签章前校验手机号-获取验证码
export function getVerify(businessId) {
	return fetch({
		url: '/insurance/insure/verify',
		method: 'get',
		params: { businessId }
	})
}

// 签章前校验手机号-校验验证码
export function verifyCode({ businessId, code }) {
	return fetch({
		url: '/insurance/insure/verifyCode',
		method: 'get',
		params: { businessId, code }
	})
}

// 校验订单是否已提交凭证
export function isUploadPayFile(businessId) {
	return fetch({
		url: '/insurance/insure/isUploadPayFile',
		method: 'get',
		params: { businessId }
	})
}

// 去支付
export function goPay(businessId, data) {
	return fetch({
		url: 'insurance/insure/goPay',
		method: 'post',
		data,
		params: { businessId },
		headers: {
			'Content-Type': 'application/json'
		}
	})
}
// 批量投保获取
export function batchInsuranceAnalysePerson(params) {
	return fetch({
		url: 'insurance/batchInsuranceAnalysePerson',
		method: 'post',
		params
	})
}
// 批量投保提交 ?customers=客户名称拼接&productId=产品ID
export function batchInsurancePersonBtn(params) {
	return fetch({
		url: 'insurance/batchInsurancePersonBtn',
		method: 'post',
		params
	})
}

// 识别身份证
export function idCardOcr(params) {
	return fetch({
		url: '/insurance/idCardOcr',
		method: 'post',
		params,
		data: params,
		headers: {
			'Content-Type': 'application/json'
		}
	})
}
// 识别行驶证
export function driveOcr(params) {
	return fetch({
		url: '/insurance/driveOcr',
		method: 'post',
		params,
		data: params,
		headers: {
			'Content-Type': 'application/json'
		}
	})
}
// 获取家协产品信息
export function guarantee(params) {
	return fetch({
		url: 'insurance/product/guarantee',
		method: 'post',
		params
	})
}
